import React from "react";
import { Tooltip } from "antd";

/**
 * fix log text due to space
 * @param text {string}
 * @param length {number}
 */
const fixLongText = (text: string, length?: number) => {
  const fixLength: number = length || 10;
  if (text.length > fixLength)
    return (
      <>
        <Tooltip placement="topLeft" title={text}>
          <p>{text.substring(0, fixLength)}...</p>
        </Tooltip>
      </>
    );
  else {
    return (
      <>
        <Tooltip placement="topLeft" title={text}>
          <p>{text}</p>
        </Tooltip>
      </>
    );
  }
};

/**
 * fixNullData
 * @param text {string}
 * @return string
 */
const fixNullData = (text?: string): string => {
  if (typeof text === undefined) {
    return "无数据";
  }
  if (text === "" || text === "nan") {
    return "无数据";
  }
  return text as string;
};

/**
 *
 * @param majorName
 */
const checkMajorNameNullOrUndefined = (majorName?: string): boolean => {
  if (typeof majorName === undefined) {
    return false;
  }
  if (majorName === "") {
    return false;
  }
  return true;
};

export { fixLongText, fixNullData, checkMajorNameNullOrUndefined };
